﻿namespace HiMap.Geometry
{
    using System;
    using System.Collections.Generic;

    public class MultiPointClass : GeometryClass, IMultiPoint, IGeometry, IGeometryCollection
    {
        protected internal double _M;
        protected internal double _X;
        protected internal double _Y;
        protected internal double _Z;
        private List<IGeometry> geoList;

        public MultiPointClass()
        {
            base._Type = GeometryType.MultiPoint;
            this._X = 0;
            this._Y = 0;
            this._Z = 0;
            this._M = 0;
            base._Envelope = new EnvelopeClass();
            this.geoList = new List<IGeometry>();
            this.geoList.Add(this);
        }

        void IGeometryCollection.AddGeometry(IGeometry Geo)
        {
            this.geoList.Add(Geo);
        }

        IGeometry IGeometryCollection.GetGeometry(int Index)
        {
            return this.geoList[Index];
        }

        void IGeometryCollection.InsertGeometry(int Index, IGeometry Geo)
        {
            this.geoList.Insert(Index, Geo);
        }

        void IGeometryCollection.RemoveGeometry(int Index, int Count)
        {
            this.geoList.RemoveRange(Index, Count);
        }

        void IGeometryCollection.SetGeometry(int Index, IGeometry NewGeo)
        {
            this.geoList[Index] = NewGeo;
        }

        IEnvelope IGeometry.Envlope
        {
            get
            {
                IEnvelope envelope = new EnvelopeClass();
                for (int i = 0; i < this.geoList.Count; i++)
                {
                    IPoint point = (IPoint) this.geoList[i];
                    if (i == 0)
                    {
                        envelope.MinX = point.X;
                        envelope.MaxX = point.X;
                        envelope.MinY = point.Y;
                        envelope.MaxY = point.Y;
                    }
                    else
                    {
                        envelope.MinX = Math.Min(point.X, envelope.MinX);
                        envelope.MaxX = Math.Max(point.X, envelope.MaxX);
                        envelope.MinY = Math.Min(point.Y, envelope.MinY);
                        envelope.MaxY = Math.Max(point.Y, envelope.MaxY);
                    }
                }
                return envelope;
            }
        }

        int IGeometryCollection.GeometryCount
        {
            get
            {
                return this.geoList.Count;
            }
        }

        double IMultiPoint.M
        {
            get
            {
                return this._M;
            }
            set
            {
                this._M = value;
            }
        }

        double IMultiPoint.X
        {
            get
            {
                return this._X;
            }
            set
            {
                this._X = value;
                base._Envelope.MinX = value;
                base._Envelope.MaxX = value;
            }
        }

        double IMultiPoint.Y
        {
            get
            {
                return this._Y;
            }
            set
            {
                this._Y = value;
                base._Envelope.MinY = value;
                base._Envelope.MaxY = value;
            }
        }

        double IMultiPoint.Z
        {
            get
            {
                return this._Z;
            }
            set
            {
                this._Z = value;
            }
        }
    }
}

